{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "be6003d4-e2ff-4ab5-a8a3-132f9cb7fc58",
   "metadata": {},
   "source": [
    "# Python的数据结构\n",
    "\n",
    "  -List 列表  \n",
    "  -Tuple 元组  \n",
    "  -Dict 字典  \n",
    "  -Set 集合"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4eddfc51-a7b7-405e-adcf-ff52481872d1",
   "metadata": {},
   "source": [
    "# List"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4be9df4b-810d-48f7-817c-bae29439a78e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 1, 2]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = []\n",
    "a.append(1)\n",
    "a.append(2)\n",
    "a.insert(0,3)\n",
    "\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b9f08ffc-9305-4f2c-addd-f14bd2612293",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 10, 6]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=[1,2,3,4,5,6]\n",
    "a[4]=10\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "430437fe-a097-4162-a042-46cb2e659577",
   "metadata": {},
   "source": [
    "# Tuple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b0cc5cea-68f8-41d6-bad9-7c7600a30cec",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[6], line 2\u001b[0m\n\u001b[1;32m      1\u001b[0m a\u001b[38;5;241m=\u001b[39m(\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m,\u001b[38;5;241m4\u001b[39m,\u001b[38;5;241m5\u001b[39m,\u001b[38;5;241m6\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m \u001b[43ma\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m4\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m10\u001b[39m\n\u001b[1;32m      3\u001b[0m a\n",
      "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "a=(1,2,3,4,5,6)\n",
    "a[4]=10\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1db0e720-831d-49f3-9ffb-d797bda35f71",
   "metadata": {},
   "source": [
    "# Dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3edc932b-3e9e-46bb-935e-c5e23590706e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: 'Sun'}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "planets = [\"Mercury\",\"Saturn\",\"Earth\",\"Venus\",\"Jupiter\",\"Mars\",\"Neptune\",\"Uranus\"]\n",
    "planets_dict={}\n",
    "planets_dict[0]=\"Sun\"\n",
    "planets_dict"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da6a54df-e51e-4ef8-bbee-64476fd53cc7",
   "metadata": {},
   "source": [
    "# Set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "dfa23a6f-4a83-471c-b061-176c4b79f9e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a={1,1,2,2,3,3}\n",
    "a\n",
    "b={1,1,2,2,3,3}\n",
    "b"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11ba69a1-a653-48f9-ac20-c0c55310be45",
   "metadata": {},
   "source": [
    "# Python的执行流程\n",
    "\n",
    "  *顺序执行  \n",
    "  *条件判断（if语句）  \n",
    "  *循环（for,while）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e01f953a-15a9-47ae-96a8-2068bd46b0f8",
   "metadata": {},
   "source": [
    "# 顺序执行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "90378988-796d-4903-8b34-d15b7c162d83",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2\n",
      "2 1\n"
     ]
    }
   ],
   "source": [
    "a = 1\n",
    "b = 2\n",
    "print(a,b)\n",
    "t = a\n",
    "a = b\n",
    "b = t\n",
    "print(a,b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c847dc4b-9e8f-4be0-b9e5-26ccfce80257",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2\n",
      "2 1\n",
      "1 2\n",
      "2 1\n"
     ]
    }
   ],
   "source": [
    "a = 1\n",
    "b = 2\n",
    "print(a,b)\n",
    "a = 2\n",
    "b = 1\n",
    "print(a,b)\n",
    "a,b=b,a\n",
    "print(a,b)\n",
    "\n",
    "a=a+b\n",
    "b=a-b\n",
    "a=a-b\n",
    "print(a,b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "150f26d1-6b3e-4a22-bafa-1d148eae987f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 条件语句\n",
    "\n",
    "  语法：  \n",
    "  if<条件判断式>：  \n",
    "    <statements1>  \n",
    "  elif<条件判断式>：\n",
    "    <statements2>\n",
    "  else:\n",
    "    <statements3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f52f6599-b9eb-4797-9fc7-1881e8d062d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "positive number\n"
     ]
    }
   ],
   "source": [
    "number = 1\n",
    "\n",
    "if number>0:\n",
    "    print(\"positive number\")\n",
    "elif number<0:\n",
    "    print(\"negatibe number\")\n",
    "else:\n",
    "    print(\"zero\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2715b34b-b1db-4c69-bb68-933b6a6842a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "PI\n"
     ]
    }
   ],
   "source": [
    "PI=3.141592658535\n",
    "\n",
    "if (PI - 3.141592658535) <1e-6:\n",
    "    print(\"PI\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c436e3bc-6c8e-46b7-b7c4-1104eb3d648c",
   "metadata": {},
   "source": [
    "# 循环语句\n",
    "\n",
    "  for 变量<条件>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "240de0e6-07d6-429a-abc2-16bd66495a5d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "463c7224-00cd-426d-ae0f-aa1a37d52025",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'fd' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[13], line 2\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mjupyturtle\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m \n\u001b[0;32m----> 2\u001b[0m \u001b[43mfd\u001b[49m(\u001b[38;5;241m50\u001b[39m)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'fd' is not defined"
     ]
    }
   ],
   "source": [
    "from jupyturtle import * \n",
    "fd(50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f670d3ba-e7f7-4fc4-9033-675dae22755c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2faa5de-c02a-4b58-be55-fce2cb8addf4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7247b1ed-a024-4a2b-82f8-65293e91cd6e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0590fc44-2e6f-4f93-86cb-ac1d102e7702",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27e4fc33-5246-41d9-ad65-d8f6a41ed4c4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7dcbcba2-00e6-4d10-8487-8016202ac3ba",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e5ff7e5-64a6-4aad-944e-376156563542",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "23a0360c-7b8d-4740-8ec5-538a1d03c167",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0e194d8c-275f-46fe-99d9-54dd4b2b9c28",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e5b5b40f-4c9d-459c-8a0f-7bd4d36079c9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5a2d1a9-2aa8-48e6-9518-dba3bcec6079",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47888ea8-02c7-49ae-9a50-95ebebaa15d9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
